package com.hong.serviceuser.controller.api;

import com.hong.commonutil.result.Result;
import com.hong.commonutil.utils.AuthContextHolder;
import com.hong.model.model.user.UserInfo;
import com.hong.model.vo.user.LoginVo;
import com.hong.model.vo.user.UserAuthVo;
import com.hong.serviceuser.service.UserInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/api/user/")
public class UserInfoApiController {
    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation("用户手机登录接口")
    @PostMapping("login")
    public Result login(@RequestBody LoginVo loginVo) {
        Map<String, Object> info = userInfoService.login(loginVo);
        return Result.ok(info);
    }
    @ApiOperation("用户认证接口")
    @PostMapping("auth/userAuth")
    public Result userAuth(@RequestBody UserAuthVo userAuthVo, HttpServletRequest request) {
        //传递用户id和用户认证的vo对象
        userInfoService.userAuth(AuthContextHolder.getUserId(request),userAuthVo);
        return Result.ok();
    }
    @ApiOperation("获取用户id信息接口")
    @GetMapping("auth/getUserInfo")
    public Result getUserInfo( HttpServletRequest request) {
        Long id = AuthContextHolder.getUserId(request);
        UserInfo userInfo=userInfoService.getById(id);
        return Result.ok(userInfo);
    }
}
